package com.poetize.plus.entity.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.poetize.plus.entity.po.Notice;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author zuosy
 * @Date 2024/3/30 14:57
 **/
public record NoticeVO(
        @Schema(description = "id")
        Long id,

        @Schema(description = "公告标题")
        String title,

        @Schema(description = "公告内容")
        String content,

        @Schema(description = "是否启用")
        Boolean status,

        @Schema(description = "创建者")
        String createBy,

        @Schema(description = "创建时间")
        @JsonFormat(pattern = "yyyy-MM-dd")
        LocalDateTime createTime
) {

    /**
     * 实体类转VO
     *
     * @param notice
     * @return
     */
    public static NoticeVO convert(Notice notice) {
        return new NoticeVO(notice.getId(), notice.getTitle(), notice.getContent(), notice.getStatus(), notice.getCreateBy(), notice.getCreateTime());
    }

    /**
     * 实体类集合转VO集合
     *
     * @param noticeList
     * @return
     */
    public static List<NoticeVO> convertList(List<Notice> noticeList) {
        List<NoticeVO> result = new ArrayList<>();
        noticeList.forEach(notice -> result.add(convert(notice)));
        return result;
    }
}
